package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumDataJavaType;
import com.cw.jeeyt.common.enums.EnumMysqlDataType;
import com.cw.jeeyt.common.enums.EnumYn;
import com.cw.jeeyt.service.bo.system.SystemColumnInfoBo;
import com.cw.jeeyt.dao.model.system.SystemColumnInfoDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * 表字段信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemColumnInfoConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemColumnInfoBo do2Bo(SystemColumnInfoDo model) {
        if (model == null) {
            return null;
        }
        String isPkCn = StringUtil.isNotBlank(model.getIsPk()) ? EnumYn.find(model.getIsPk())
            .getDescription() : "";
        String columnSqlTypeCn = StringUtil.isNotBlank(model.getColumnSqlType()) ? EnumMysqlDataType.find(
            model.getColumnSqlType())
            .getDescription() : "";
        String columnTypeCn = StringUtil.isNotBlank(model.getColumnType()) ? EnumDataJavaType.find(
            model.getColumnType())
            .getDescription() : "";
        SystemColumnInfoBo bo = new SystemColumnInfoBo();
        bo.setId(model.getId());
        bo.setTableId(model.getTableId());
        bo.setColumnCode(model.getColumnCode());
        bo.setColumnName(model.getColumnName());
        bo.setColumnLength(model.getColumnLength());
        bo.setColumnType(model.getColumnType());
        bo.setColumnTypeCn(columnTypeCn);
        bo.setColumnSqlCode(model.getColumnSqlCode());
        bo.setColumnSqlType(model.getColumnSqlType());
        bo.setColumnSqlTypeCn(columnSqlTypeCn);
        bo.setIsPk(model.getIsPk());
        bo.setIsPkCn(isPkCn);
        bo.setIsDict(model.getIsDict());
        bo.setDictCode(model.getDictCode());
        bo.setDictType(model.getDictType());
        bo.setIsAmt(model.getIsAmt());
        bo.setIsNumber(model.getIsNumber());
        bo.setIsRate(model.getIsRate());
        bo.setIsDate(model.getIsDate());
        bo.setColumnComment(model.getColumnComment());
        bo.setIsQueryColumn(model.getIsQueryColumn());
        bo.setIsOrderColumn(model.getIsOrderColumn());
        bo.setIsListColumn(model.getIsListColumn());
        bo.setIsFormColumn(model.getIsFormColumn());
        bo.setOrderType(model.getOrderType());
        bo.setQueryType(model.getQueryType());
        bo.setIsStrDate(model.getIsStrDate());
        bo.setIsRequired(model.getIsRequired());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        bo.setIsTextarea(model.getIsTextarea());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemColumnInfoDo bo2Do(SystemColumnInfoBo bo) {
        if (bo == null) {
            return null;
        }
        SystemColumnInfoDo model = new SystemColumnInfoDo();
        model.setId(bo.getId());
        model.setTableId(bo.getTableId());
        model.setColumnCode(bo.getColumnCode());
        model.setColumnName(bo.getColumnName());
        model.setColumnLength(bo.getColumnLength());
        model.setColumnType(bo.getColumnType());
        model.setColumnSqlCode(bo.getColumnSqlCode());
        model.setColumnSqlType(bo.getColumnSqlType());
        model.setIsPk(bo.getIsPk());
        model.setIsDict(bo.getIsDict());
        model.setDictCode(bo.getDictCode());
        model.setDictType(bo.getDictType());
        model.setIsAmt(bo.getIsAmt());
        model.setIsNumber(bo.getIsNumber());
        model.setIsRate(bo.getIsRate());
        model.setIsDate(bo.getIsDate());
        model.setColumnComment(bo.getColumnComment());
        model.setIsQueryColumn(bo.getIsQueryColumn());
        model.setIsOrderColumn(bo.getIsOrderColumn());
        model.setIsListColumn(bo.getIsListColumn());
        model.setIsFormColumn(bo.getIsFormColumn());
        model.setOrderType(bo.getOrderType());
        model.setQueryType(bo.getQueryType());
        model.setIsStrDate(bo.getIsStrDate());
        model.setIsRequired(bo.getIsRequired());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        model.setIsTextarea(bo.getIsTextarea());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemColumnInfoBo> doList2BoList(List<SystemColumnInfoDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemColumnInfoConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemColumnInfoDo> boList2DoList(List<SystemColumnInfoBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemColumnInfoConverter::bo2Do));
    }
}
